<?php 

session_start();
$id_item = $_GET['cmd'];
$login = $_SESSION['login'];

$hostname = "localhost";
$username = "root";
$password = "";
$database = "krestikii-noliki";

	$link = @mysql_connect($hostname, $username, $password);
	if(!$link){
		echo('BD->Connect: With out connect!');
	}
	
	mysql_set_charset("utf8",$link);
	
	if(!@mysql_select_db($database)){
		echo('BD->Select: Select db!');
	}

	$date = date("Y-m-d H:i:s");

	$query = 'INSERT INTO  `moves` (
				`login` ,
				`move`,
				`date`)
				VALUES ( \''.$login.'\',  \''.$id_item.'\', \''.$date.'\')';
	//var_dump($query);

	$result = mysql_query($query);
	if(!$result){
		echo('BD->Query: Bad query!');
	}

	$query = 'SELECT * FROM `moves` WHERE `date` > \''.$date.'\' AND `login` != \''.$login.'\'';;
	//var_dump($query);

	$result = mysql_query($query);
	if(!$result){
		echo('BD->Query: Bad query!');
	}

	while($fetch = mysql_fetch_array($result, MYSQL_ASSOC)){
		//var_dump($fetch);
		for ($i=0; $i<10 ; $i++) { 
			for ($j=0; $j<10 ; $j++) {
				$map[$i][$j] = 'o'; 
			}

		}
	}

//var_dump($_SESSION);

echo json_encode($id_item);
//echo json_encode($map);

?>